$(function () {
    var pid = $('#pid').text();
    $.get('/movie/info_media/', {'type': 1, 'pid': pid}, function (data) {
        data = JSON.parse(data);
        if (data.status == 200) {
            $('#host_img').attr('src', data.info.url);
            // 调整图片大小
            if (data.info.width > data.info.height) {
                var height = data.info.height * $('#host_img').width() / data.info.width;
                $('.big_img img').css('height', height);
            } else {
                var width = data.info.width * $('#host_img').height() / data.info.height;
                $('.big_img img').css('width', width);
                $('.big_img h1').css('width', width);
            }

            $('#img_download').attr('href', '/picture/download/?picture_id=' + pid + '&url=' + data.info.url);
            $('#star').text(data.info.star_num);
            $('#parise').text(data.info.parise_num);
            $('#share_img').attr('href', data.info.url);

            // 获取该电影其他图片
            $.get('/picture/movie_imgs/', {'movie_id': data.info.movie_id}, function (movie_pictures) {
                movie_pictures = JSON.parse(movie_pictures);
                if (movie_pictures.status == 200) {
                    $('.om_img').html("");
                    var k = 0;
                    for (var i=0;;i++) {
                        var row = movie_pictures.info[i];
                        if (row.id != pid) {
                            var str = '<a href="/picture/single/?pid=' + row.id + '"><img src="' + row.url + '" alt=""></a>';
                            $('.om_img').append(str);
                            k++;
                        }
                        if (k == 4) break;
                    }
                } else {
                }
            });

            // 获取该电影基本信息
            $.get('/movie/info_media/', {'mid': data.info.movie_id, 'type': 0}, function (movie_info) {
                movie_info = JSON.parse(movie_info);
                if (movie_info.status == 200) {
                    $('#movie_name').text(movie_info.info.movie_name);
                    $('#movie_name').attr('href', '/movie/single/?movie_id=' + movie_info.info.id);
                    $('#directors').text('导演：' + movie_info.info.directors);
                    $('#score').text('豆瓣评分：' + movie_info.info.score);
                }

            });

            // 获取该场景其他图片
            $.get('/picture/sence_image/', {'pid': data.info.id}, function (secce_pictures) {
                secce_pictures = JSON.parse(secce_pictures);
                if (secce_pictures.status == 200) {
                    $('.sidebar_thumbs').html("");
                    for (var i = 0; i < secce_pictures.info.length; i++) {
                        var row = secce_pictures.info[i];
                        var str = '<a href="/picture/single/?pid=' + row.id + '"><img src="' + row.url + '" alt=""></a>';
                        $('.sidebar_thumbs').append(str);
                    }
                } else {
                }
            });

            // 获取该图片标签
            $.get('/picture/class/', {'pid': data.info.id}, function (target_pictures) {
                target_pictures = JSON.parse(target_pictures);
                if (target_pictures.status == 200) {
                    $('#targets').html("");
                    var str = '<a title="小编精选" href="" class="award"><i class="iconfont icon-jiangzhang"></i></a>';
                    for (var i=0; i < Math.min(target_pictures.info.length, 12); i++) {
                        var row = target_pictures.info[i];
                        str += '<a href="">' + row.target + '</a>';
                    }
                    $('#targets').append(str);
                } else {}
            });

            // 获取评论
            setTimeout(get_comment(data.info.movie_id),2000);
        } else {

        }
    });

    // 标签显示
    $(".big_img").hover(
        function (e) {
          e.currentTarget.children[1].style.opacity = 1;
        },
        function (j) {
          j.currentTarget.children[1].style.opacity = 0;
    });

});